package com.dykj.fireFighting.web.rocketmq.consumer;

import com.alibaba.fastjson.JSON;
import com.dykj.fireFighting.api.elasticsearch.devHisZc.entity.EsDevHisZc;
import com.dykj.fireFighting.api.elasticsearch.devHisZc.service.EsDevHisZcService;
import com.dykj.fireFighting.common.starter.redisson.service.RedisService;
import com.dykj.fireFighting.web.model.report.DevHisZc;
import com.dykj.fireFighting.web.rocketmq.message.InsertDevHisZcMessage;
import com.dykj.fireFighting.web.service.DevHisZcService;
import com.dykj.fireFighting.web.utils.SpringUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhengbo
 */
//@RocketMQMessageListener(
//        topic = InsertDevHisZcMessage.TOPIC,
//        consumerGroup = "dy-consumer-group-" + InsertDevHisZcMessage.TOPIC
//)
public class InsertDevHisZcConsumer implements RocketMQListener<InsertDevHisZcMessage> {
    public static final Logger LOGGER = LoggerFactory.getLogger(InsertDevHisZcConsumer.class);
    private static final RedisService redisService= SpringUtil.getBean(RedisService.class);
    private static final DevHisZcService devHisZcService= SpringUtil.getBean(DevHisZcService.class);
    private static final EsDevHisZcService esDevHisZcService= SpringUtil.getBean("esDevHisZcService");
    @Override
    public void onMessage(InsertDevHisZcMessage insertDevHisZcMessage) {
//        DevHisZc devHisZc =  insertDevHisZcMessage.getDevHisZc();
//        LOGGER.info("===========插入devHis数据到mysql==============");
//        devHisZcService.insertDevHisZc(devHisZc);
//        LOGGER.info("===========插入EsDevHis数据到ES==============");
//        EsDevHisZc esDevHisZc = new EsDevHisZc();
//        BeanUtils.copyProperties(devHisZc, esDevHisZc);
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        esDevHisZc.setUpTime(sdf.format(devHisZc.getUpTime()));
//        esDevHisZc.setZtfssj(sdf.format(devHisZc.getZtfssj()));
//        esDevHisZc = esDevHisZcService.importAll(esDevHisZc);
//        LOGGER.info("===========插入EsDevHis数据到ES:=============" + JSON.toJSONString(esDevHisZc));
//
//        redisService.set(devHisZc.getId(), JSON.toJSONString(devHisZc), 3600L);
    }
}
